using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace HBFramework
{
    public partial class MessageManager
    {
        /// <summary>
        /// 发消息
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="args"></param>
        public void SendMessage(int messageId, Message arg)
        {
            //消息字典
            if (messageDict_message.ContainsKey(messageId))
            {
                messageDict_message[messageId]?.Invoke(arg);
            }
            else
            {
                DebugUtility.Log("MessageManager", $"messageDict_message中不包含{messageId}消息");
            }
        }

        /// <summary>
        /// 注册消息
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="act"></param>
        public void RegisterMessage(int messageId, Action<Message> act)
        {
            if (!messageDict_message.ContainsKey(messageId))
                messageDict_message.Add(messageId, null);
            messageDict_message[messageId] += act;
        }

        /// <summary>
        /// 取消注册消息
        /// </summary>
        /// <param name="message"></param>
        /// <param name="act"></param>
        public void UnregisterMessage(int messageId, Action<Message> act)
        {
            if (!messageDict_message.ContainsKey(messageId))
            {
                DebugUtility.LogWarning("MessageManager", $"messageDict_message中不包含{messageId}消息");
                return;
            }

            messageDict_message[messageId] -= act;
        }
    }

    public abstract class Message
    {
    }
}